define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'member/index',
                    add_url: 'member/add',
                    edit_url: 'member/edit',
                    del_url: 'member/del',
                    multi_url: 'member/multi',
                    table: 'member',
                },queryParams: function (params) {
                    console.log(window.location.href);
                    var url_http=window.location.href;
                    var url=url_http.match(/ids(.*?)[1-9]\d*/g);
                    if(url != null){
                        if(url.length>0){
                            params.ids= url[0].replace('ids/',"");
                        }
                    }
                    console.log(params.id = Config.id);
                    return params;
                }
            });

            var table = $("#table");
            var url = 'member/mate/from_uid/'+Config.id;
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_name', title: __('User_name')},
                        {field: 'wechat_name', title:'微信昵称'},
                        {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'wechat', title: __('Wechat')},
                        {field: 'avatar', title: __('Avatar'),formatter: Table.api.formatter.image, operate: false},
                        {field: 'headimgurl', title:'微信头像',formatter: Table.api.formatter.image, operate: false},
                        {field: 'gender', title: __('Gender'), searchList: {"0":__('Gender 0'),"1":__('Gender 1')}, formatter: Table.api.formatter.normal},
                        {field: 'live_city', title: __('Live_city')},
                        {field: 'age', title:'年龄'},
                        {field: 'height', title:'身高'},
                        {field: 'education.name', title: __('教育状况')},
                        {field: 'marriage.name', title: __('婚况')},
                        {field: 'mate_age', title:'匹配年龄'},
                        {field: 'mate_height', title: "匹配身高"},
                        {field: 'mate_marriage', title: "匹配婚况"},
                        {field: 'mate_education', title: "匹配教育"},
                        {field: 'id', title:"匹配", table: table,events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: '匹配',
                                    text:"匹配",
                                    title: "匹配",
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-list',
                                    url: url,
                                    callback: function (data) {
                                        console.log('callback');
                                        console.log(data);
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        console.log('visible');
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                }],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'is_mate', title:'匹配状态', searchList: {"0":"不匹配","1":"开始匹配","2":"已匹配"}, formatter: Table.api.formatter.status},
                        {field: 'authen_status', title: __('Authen_status'), searchList: {"0":__('Authen_status 0'),"1":__('Authen_status 1')}, formatter: Table.api.formatter.status},
                        {field: 'rec_status', title: __('Rec_status'), searchList: {"0":__('Rec_status 0'),"1":__('Rec_status 1')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        /*{field: 'car.name', title: __('车辆状况')},*/
                        /*{field: 'house.name', title: __('房产状况')},*/
                        /*{field: 'income.name', title: __('收入状况')},*/
                        /*{field: 'zodiac.name', title: __('星座')},*/
                        /*{field: 'tags.title', title: __('标签')},*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});